package com.example.demo1.user.service.impl;

import com.example.demo1.user.dao.IUserDao;
import com.example.demo1.user.dao.impl.UserDaoImpl;
import com.example.demo1.user.service.IUserService;
import com.example.demo1.utils.StringUtil;

import java.sql.Connection;
import java.util.List;

public class UserServiceImpl implements IUserService {
    IUserDao userDao = new UserDaoImpl();
    Connection conn;

    @Override
    public Boolean loginCheck(String username, String password, Object... params) {
        String sql = "SELECT * FROM users where username='" + username + "' AND password='" + password + "'";
        List dataList = userDao.getDataList(conn, sql);
        if (null != dataList && dataList.size() != 0) {
            System.out.println(dataList);
            return true;
        }
        return false;
    }

    /**
     * 注册页面添加信息
     *
     * @param username 用户名
     * @param password 密码
     * @param params
     * @return false表示用户信息未完善
     */
    @Override
    public Boolean insertUser(String username, String password, Object... params) {
        String sql = "INSERT INTO users (username,password) VALUES ('" + username + "','" + password + "') ";
        System.out.println(sql);
        if (!StringUtil.infoInputCheck(username, password)) {
            System.out.println("请完善信息!");
            return false;
        }
        if (userDao.saveData(sql) == 0) {
            System.out.println("添加失败！");
            return false;
        }
        return true;
    }
}
